<template>
  <el-breadcrumb separator="/">
    <el-breadcrumb-item v-for="(item, index) in breadcrumbs" :key="index">
      <span v-if="index === breadcrumbs.length - 1" class="no-redirect">
        {{ item.meta.title }}
      </span>
      <router-link v-else :to="item.path">
        {{ item.meta.title }}
      </router-link>
    </el-breadcrumb-item>
  </el-breadcrumb>
</template>

<script>
import { computed } from "vue";
import { useRoute } from "vue-router";

export default {
  setup() {
    const route = useRoute();

    const breadcrumbs = computed(() => {
      const matched = route.matched.filter(
        (item) => item.meta && item.meta.title
      );
      return matched;
    });

    return {
      breadcrumbs,
    };
  },
};
</script>

<style scoped>
.no-redirect {
  color: #97a8be;
  cursor: text;
}
</style>
